//
//  SongsListSqureCollectionViewCell.m
//  LuckyRadio
//
//  Created by Mr、J on 15/11/19.
//  Copyright © 2015年 chenjun. All rights reserved.
//

#import "SongsListSqureCollectionViewCell.h"
#import <UIImageView+WebCache.h>

#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width

#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

#define WIDTH_PRO(X) (X)*(SCREEN_WIDTH/375)

#define HEIGHT_PRO(Y) (Y)*(SCREEN_HEIGHT/667)
@implementation SongsListSqureCollectionViewCell
- (void)dealloc
{
    [_songsListSqureModel release];
    [_image release];
    [_tagImageView release];
    [_listenCountLabel release];
    [_titleLabel release];
    [super dealloc];
}

-(instancetype)initWithFrame:(CGRect)frame
{
    if ([super initWithFrame:frame]) {
        
        [self createSubViews];
    }
    
    return self;
}

-(void)createSubViews
{
    self.image = [UIImageView new];
    [self.contentView addSubview:self.image];
    self.image.image = [UIImage imageNamed:@"image.jpg"];
    [_image release];
    
    self.titleLabel = [UILabel new];
    self.titleLabel.font = [UIFont systemFontOfSize:15];
    self.titleLabel.numberOfLines = 0;

    [self.contentView addSubview:self.titleLabel];
    [_titleLabel release];
    
    self.tagImageView = [UIImageView new];
    [self.image addSubview:self.tagImageView];
    [_tagImageView release];
    
    self.listenCountLabel = [UILabel new];
    self.listenCountLabel.textColor = [UIColor whiteColor];
    self.listenCountLabel.shadowColor = [UIColor blackColor];
    self.listenCountLabel.font = [UIFont systemFontOfSize:12];
    self.listenCountLabel.textAlignment = NSTextAlignmentRight;
    [self.image addSubview:self.listenCountLabel];
    [_listenCountLabel release];
    
    
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    self.image.frame = CGRectMake(0, 0, (SCREEN_WIDTH - WIDTH_PRO(30)) / 2, (SCREEN_WIDTH - WIDTH_PRO(30)) / 2);
    self.titleLabel.frame = CGRectMake(0, self.image.frame.size.height + HEIGHT_PRO(10), (SCREEN_WIDTH - WIDTH_PRO(30)) / 2, HEIGHT_PRO(40));
    
//    CGRect listenerRect = [self.listenCountLabel.text boundingRectWithSize:CGSizeMake(320, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:self.listenCountLabel.font,NSFontAttributeName, nil] context:nil];
    self.listenCountLabel.frame = CGRectMake(self.image.frame.size.width - WIDTH_PRO(60), HEIGHT_PRO(5), WIDTH_PRO(50), HEIGHT_PRO(20));
    
    self.tagImageView.frame = CGRectMake(self.image.frame.size.width - self.listenCountLabel.frame.size.width - WIDTH_PRO(25), HEIGHT_PRO(9), WIDTH_PRO(12), HEIGHT_PRO(12));
}

-(void)setSongsListSqureModel:(SongsListSqureModel *)songsListSqureModel
{
    if (_songsListSqureModel != songsListSqureModel) {
        [_songsListSqureModel release];
        _songsListSqureModel = [songsListSqureModel retain];
    }
    [self.image sd_setImageWithURL:[NSURL URLWithString:songsListSqureModel.pic_url] placeholderImage:[UIImage imageNamed:@"Read_zhanwei"]];
    self.titleLabel.text = songsListSqureModel.title;
    
    self.tagImageView.image = [UIImage imageNamed:@"iconfont-headphone"];
    
    self.listenCountLabel.text = [NSString stringWithFormat:@"%@", songsListSqureModel.listen_count];
    
    if ([songsListSqureModel.listen_count floatValue] > 10000) {
        CGFloat count = [songsListSqureModel.listen_count floatValue] / 10000;
        self.listenCountLabel.text = [NSString stringWithFormat:@"%.1f万", count];
    }

    
    
    
    
}



@end
